//
// Created by MikeChen on 2025/3/29.
// do while循环 直到型循环


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {
    int count = 0;
    do {
        printf("Hello!,%d\n", count);
    } while (count++ < 5);

    //计算1~100的和
    printf("................\n");
    int i = 0, sum = 0;
    do {
        sum += i;
    } while (++i <= 100);
    printf("1到100的和:%d\n", sum);


    //综合练习,看三种循环的区别
    // 求 1-2+3-4...+99-100的结果
    printf("................\n");
    sum = 0;
    for (i = 1; i <= 100; ++i) {
        if (i % 2 == 0)
            sum -= i;
        else
            sum += i;
    }
    printf("1-2+3-4...+99-100 = %d\n", sum);

    printf("................\n");
    sum = 0;
    i = 0;
    while (++i <= 100) {
        if (i % 2 == 0)
            sum -= i;
        else
            sum += i;
    }
    printf("1-2+3-4...+99-100 = %d\n", sum);

    printf("................\n");
    sum = 0;
    i = 1;
    do {
        if (i % 2 == 0)
            sum -= i;
        else
            sum += i;
    } while (++i <= 100);

    printf("1-2+3-4...+99-100 = %d\n", sum);
    system("read -rsp $'Press enter to continue...\\n'");
    return EXIT_SUCCESS;
}
